from pathlib import Path
import matplotlib.pyplot as plt
import csv
from datetime import datetime

path = Path('sitka_weather_2021_full.csv')
lines = path.read_text().splitlines()

reader = csv.reader(lines)
header_row = next(reader)

for index,column_header in enumerate(header_row):
    print(index,column_header)

# 提取数据
dates , prcps = [] , []
for row in reader:
    current_date = datetime.strptime(row[2],"%Y-%m-%d")
    prcp = float(row[5])
    dates.append(current_date)
    prcps.append(prcp)

# 根据降雨量绘图
plt.style.use('seaborn-v0_8')
fig,ax = plt.subplots()

ax.plot(dates,prcps,color='blue')
ax.set_title("Daily prcp, 2021 sitka",fontsize = 16)
ax.set_xlabel('',fontsize=16)
fig.autofmt_xdate()
ax.set_ylabel('Prcp',fontsize=16)

plt.show()